/* --- 颜色和主题变量 --- */
:root {
    --primary-color: #2970FF;
    --primary-color-rgb: 41, 112, 255;
    --background-color: #f8f9fa;
    --card-background: #ffffff;
    --text-color: #212529;
    --muted-text-color: #6c757d;
    --border-color: #e9ecef;
    --success-color: #198754;
    --warning-color: #ffc107;
    --error-color: #dc3545;
    --purple-color: #6f42c1;
    --shadow-color: rgba(0, 0, 0, 0.06);
    --switch-off-color: #ced4da;
    --table-header-bg: #f8f9fa;
    --table-row-hover: rgba(41, 112, 255, 0.07);
}

[data-theme="dark"] {
    --primary-color: #4285f4;
    --primary-color-rgb: 66, 133, 244;
    --background-color: #121212;
    --card-background: #1e1e1e;
    --text-color: #e9ecef;
    --muted-text-color: #adb5bd;
    --border-color: #343a40;
    --success-color: #198754;
    --warning-color: #ffc107;
    --error-color: #dc3545;
    --purple-color: #9b72cf;
    --shadow-color: rgba(0, 0, 0, 0.3);
    --switch-off-color: #495057;
    --table-header-bg: #212529;
    --table-row-hover: rgba(66, 133, 244, 0.1);
}

/* --- 全局和基础样式 --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
    padding: 20px;
    max-width: 1100px;
    margin: 0 auto;
    transition: background-color 0.3s, color 0.3s;
}

.container {
    display: flex;
    flex-direction: column;
    gap: 25px;
}

/* --- 头部 --- */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

h1 {
    font-size: 1.5rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    height: 32px;
}

.theme-toggle {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 6px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--muted-text-color);
    transition: all 0.2s;
}
.theme-toggle:hover {
    background-color: var(--border-color);
}


/* --- 输入区域 --- */
.input-section {
    background-color: var(--card-background);
    padding: 30px;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: 0 5px 20px var(--shadow-color);
}

.input-section h2 {
    margin-bottom: 8px;
    font-size: 1.5rem;
}

.input-section p {
    margin-bottom: 20px;
    color: var(--muted-text-color);
}

textarea {
    width: 100%;
    height: 160px;
    padding: 15px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    resize: vertical;
    font-family: 'Menlo', 'Consolas', monospace;
    background-color: var(--background-color);
    color: var(--text-color);
    margin-bottom: 15px;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(var(--primary-color-rgb), 0.25);
}

/* --- 操作行 (按钮和开关) --- */
.action-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 20px;
    margin-top: 10px;
}

button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 12px 24px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
}

button:hover {
    opacity: 0.85;
    transform: translateY(-2px);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.toggles-container {
    display: flex;
    align-items: center;
    gap: 25px;
    flex-wrap: wrap;
}

.view-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
}

.view-toggle-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--muted-text-color);
}

.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
}

.switch input { display: none; }

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--switch-off-color);
    transition: .4s;
    border-radius: 26px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

input:checked + .slider { background-color: var(--primary-color); }
input:checked + .slider:before { transform: translateX(22px); }

/* --- 结果区域 --- */
.results-section.card-view {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

.key-card {
    background-color: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 15px var(--shadow-color);
    border-top: 4px solid var(--primary-color);
}

.key-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px var(--shadow-color);
}

.key-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 20px;
    font-weight: 600;
}

.masked-key {
    font-family: 'Menlo', 'Consolas', monospace;
    font-size: 0.9em;
    background-color: var(--background-color);
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    max-width: 230px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border: 1px solid var(--border-color);
}

.key-status {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}

.status-normal { background-color: var(--success-color); color: white; }
.status-warning { background-color: var(--warning-color); color: #333; }
.status-error { background-color: var(--error-color); color: white; }

.key-detail {
    margin: 12px 0;
    font-size: 0.95rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}
.key-detail:last-child { border-bottom: none; padding-bottom: 0; }
.key-detail span:first-child { color: var(--muted-text-color); }
.key-detail span:last-child { font-weight: 600; }

.balance-highlight { font-weight: bold; color: var(--success-color); }
.low-balance { color: var(--warning-color); font-weight: bold; }
.charge-balance-highlight { font-weight: bold; color: var(--purple-color); }

/* --- 表格视图 --- */
.results-section.table-view { overflow-x: auto; }
.results-table {
    width: 100%;
    border-collapse: collapse;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 15px var(--shadow-color);
    background-color: var(--card-background);
}
.results-table th, .results-table td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}
.results-table thead th {
    background-color: var(--table-header-bg);
    font-weight: 600;
    cursor: pointer;
    user-select: none;
}
.results-table thead th:hover { background-color: rgba(var(--primary-color-rgb), 0.1); }
.results-table tbody tr:hover { background-color: var(--table-row-hover); }
.results-table td .masked-key { max-width: 200px; }

/* --- 加载动画 --- */
.loader {
    display: none;
    text-align: center;
    padding: 40px;
}
.spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top: 4px solid var(--primary-color);
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}
@keyframes spin { 100% { transform: rotate(360deg); } }

/* --- 复制提示 --- */
.copy-tooltip {
    position: absolute;
    top: -36px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(33, 33, 33, 0.9);
    color: #fff;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 1000;
}
.copy-tooltip.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(-5px);
}

/* --- 页脚 --- */
.site-footer {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    text-align: center;
    font-size: 0.9rem;
    color: var(--muted-text-color);
}
.site-footer p { margin: 6px 0; }
.site-footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}
.site-footer a:hover { text-decoration: underline; }

/* --- 响应式设计 --- */
@media (max-width: 768px) {
    header { flex-direction: column; align-items: flex-start; }
    .action-row { flex-direction: column; align-items: stretch; }
    .toggles-container { justify-content: space-between; }
}
